import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * La clase gasolina proporciona gasolina al automovil del jugador para que pueda continuar jugando.
 * 
 * @author Asael Hernández García  
 * @version (a version number or a date)
 */
public class Gasolina extends Bonificacion
{
    /**
     * Act - do whatever the Gasolina wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private SimpleTimer timer;
    private GreenfootImage imagen;
    private GreenfootSound gas;
    
    public Gasolina()
    {
        timer = new SimpleTimer();
        timer.mark();
        resetPixels();
        imagen = new GreenfootImage("Gasolina.png");
        setImage(imagen);
        gas = new GreenfootSound("gasolina.wav");
        gas.setVolume(80);
    }
    
    public void act() 
    {
        mover();
        if(isTouching(Jugador.class)){
            gas.play();
            ((PistaAutomovil)getWorld()).addGas(5);
            ((PistaAutomovil)getWorld()).removeObs(this);
        }
        else
            if(timer.millisElapsed() > 400){
                if(getImage().getWidth() >= 10 && getImage().getHeight()>= 10)
                    disminuyeTam(getImage().getWidth()-getPixels(), getImage().getHeight()-getPixels());  
                if(getY() <= getWorld().getHeight()/2)    
                    ((PistaAutomovil)getWorld()).removeObs(this);
                timer.mark();
                addPixels();
               }    
    }    
}
